
package arffreader;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

/**
 *
 */
public class HeaderCopier {

    /**
     * Copia la cabecera
     */
    public void CopiaCabecera(FileReader fRead, FileWriter fWrite) throws IOException {
        String linea = null;

        BufferedReader br;
        BufferedWriter bw;

        br = new BufferedReader(fRead);
        bw = new BufferedWriter(fWrite);
        try {
            while ((linea = br.readLine()) != null) {
                if (linea.contains("@DATA") || linea.contains("@data")) {
                    bw.write(linea, 0, linea.length());
                    bw.write("\n");
                    
                    bw.close();
                    br.close();
                    return;
                }
                bw.write(linea, 0, linea.length());
                bw.write("\n");
            }
        } catch (IOException ex) {
            bw.close();
            br.close();
            throw ex;
        }
    }
    
    public void CopiaCabecera(String fRead, String fWrite) throws IOException {

        FileReader fr = new FileReader(fRead);
        FileWriter fw = new FileWriter(fWrite);
        CopiaCabecera(fr, fw);
        fr.close();
        fw.close();
    }
}
